//
//  TZPBLCell.m
//  wangYiLottery
//
//  Created by mac on 16/2/16.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZPBLCell.h"
#import "TZPBLModel.h"

@interface TZPBLCell ()
@property (nonatomic, strong) UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UIImageView *backImageView;
@property (nonatomic, copy) NSString *backImage;
@end
@implementation TZPBLCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
}

- (void)setupView
{
    UIImageView *imageView = [UIImageView new];
    [self.contentView addSubview:imageView];
    self.imageView = imageView;
    
    self.backgroundColor = [UIColor orangeColor];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageView.frame = self.bounds;
}

- (void)setModel:(TZPBLModel *)model {
    _model = model;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
//    [[self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img]] placeholderImage:[UIImage imageNamed:@"xuanHeight"]];
//    self.iconView = [[UIImageView alloc] init];
//    [self addSubview:self.iconView];
//    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self);
//    }];
//    [UIView animateWithDuration:10.0 animations:^{
//        
//        
//        [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"xuanHeight"]];
//        
//        NSLog(@"2");
//    }];
    self.iconView = [[UIImageView alloc] init];
    [self addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
//    self.iconView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"userIcon"]];
//    [self.iconView sizeToFit];
    self.iconView.image = [UIImage imageNamed:@"userIcon"];
//    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"userIcon"]];
    [[[NSOperationQueue alloc] init] addOperationWithBlock:^{
        //子线程加载数据
        NSURL *url = [NSURL URLWithString:model.img];
        NSData *data = [[NSData alloc] initWithContentsOfURL:url];
        UIImage *image = [UIImage imageWithData:data];
        //主线程加载数据
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
//            self.iconView.image = nil;
            self.iconView.image = image;
        }];
    }];
    self.backImageView = self.iconView;
//    self.backImage = model.img;
}

@end
